package com.dongnam.quanly.web;

import java.sql.Timestamp;
import java.util.Date;

import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.DateTimeConverter;
import javax.faces.convert.FacesConverter;

@FacesConverter("com.dongnam.quanly.web.TimestampConverter")
public class TimestampConverter extends DateTimeConverter {

	@Override
	public void setPattern(String pattern) {
		super.setPattern(pattern);
	}

	@Override
	public String getPattern() {
		return super.getPattern();
	}

	@Override
	public Object getAsObject(FacesContext context, UIComponent component, String value) {
		Date date = (Date) super.getAsObject(context, component, value);
		Timestamp timestamp = new Timestamp(date.getTime());
		return timestamp;
	}

	@Override
	public String getAsString(FacesContext context, UIComponent component, Object value) {
		Timestamp timestamp = (Timestamp) value;
		Date date = new Date(timestamp.getTime());
		return super.getAsString(context, component, date);
	}

}
